<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<?php 
$univer = $_POST['univer'];
$cname = mysql_real_escape_string($_POST['cname']);
$maincont = mysql_real_escape_string($_POST['maincont']);
$authorised = $_POST['authorised'];
	
if(isset($_POST['savecourse']))
{
	
	if($_GET['m']!=edit)
	{
				
			
		mysql_query("INSERT INTO course(`univer_id`, `course_name`, `desc`, `active_status`, `created_datetime`)
											   VALUES ('$univer','$cname','$maincont','$authorised',now())");	
		echo "<script>window.location='index.php?tc=add_course&_s=1'</script>";
	}
	
}
if(isset($_POST['updatecourse']))

{


mysql_query("UPDATE course  SET `univer_id` = '$univer',`course_name`='$cname',`desc`='$maincont',`active_status` ='$authorised',
			`modified_datetime`=now() where id='".$_POST['hid']."'")
or 
die(mysql_error());

	
	echo "<script>window.location='index.php?tc=course&_s=1'</script>";
	
}
?>
<?php if($_REQUEST['_s'] == 1){ ?>
    <div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Successfully saved.</div>
<?php } ?>
<?php if($_REQUEST['_e'] == 1){ ?>
    <div class="sucmsg"><img src="images/error.png" align="absmiddle" />&nbsp;</div>
<?php } ?>
<?php 

 $ssql="select * from course where id='".$_GET['_d']. "'";
$ssql=mysql_query($ssql);
$row =mysql_fetch_array($ssql);
if($row['active_status']=='1')
{
	
$chkact = 'checked="checked"';
}
if($row['active_status']=='0')
{
	
$chkdec = 'checked="checked"';
}
?>
<script type="text/javascript">
function validate()
{
	if(document.up.cname.value=="")
	{
		alert("Course Name Missing.");	
		document.up.cname.focus();
		return false;
	}
}
</script>
<form name="up" action="#" method="post" onSubmit="return validate()">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<input type="hidden" name="hid" value="<?php echo  $row['id'];?>" />
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left" class="righthead">Course</div>
        <div style="float:right"><a href="index.php?tc=course" class="back">View Course</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="left" width="150">University</td>
    <td align="left">
    <select name="univer" id="univer" class="txtborder" style="width:220px;">
    
    <?php 
	
$ads=mysql_query("select * from university where active_status='1' order by id ASC");
while($tech=mysql_fetch_array($ads)){
		
	?>
  
    <option <?php if($row['univer_id']==$tech['id']){echo "selected";}?> value="<?php echo $tech['id']?>">
	<?php echo $tech['university_name']?></option>
    <?php }?>
    </select> 
    
    </td>
</tr>
<tr>
	<td align="left" width="150">Course Name *</td>
    <td align="left"><input type="text" name="cname" style="width:200px;" value="<?php echo  $row['course_name'];?>"  /></td>
</tr
><!--<tr>

    <td align="left" colspan="2">
    	Course  Description
     <textarea name="maincont" id="maincont" class="textarea" cols="25" rows="5"><?php echo $row['desc'];?></textarea>
     <script type="text/javascript">CKEDITOR.replace( 'maincont',{skin : 'kama'});</script>
    </td>
</tr>-->
<tr>
  <td align="right" width="150">Status :</td>
  <td align="left">
  <input name="authorised" type="radio"  value="1" <?php echo $chkact;?> />&nbsp;Active&nbsp;&nbsp;
  <input  name="authorised" type="radio" value="0" <?php echo $chkdec;?> />&nbsp;Deactive</td>
</tr>

<tr>
	<td colspan="2" style="padding-left:155px;">
    	<?php if($_GET['m']!=edit){?>
        <input type="submit" value="Save" name="savecourse" >&nbsp;&nbsp;
        <?php }
        else
		{
         ?>
          <input type="submit" value="Update" name="updatecourse" >
         <?php 
		
		}
         ?>
    </td>
</tr>        
</table>   
</form> 
